import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:saas_order_meal/ui/food_menu_container_widget.dart';
import 'package:saas_order_meal/viewmodel/request_day_menu_view_model.dart';

import '../model/order_request_data.dart';
import '../net/net_response/menu/regular_menu_data.dart';
import '../viewmodel/regular_menu_contain_view_model.dart';

class RequestDayMenuWidget extends BaseStatefulMvvmWidget {
  final OrderRequestData orderData;
  String orderDate;
  OnFoodSelectListener? selectListener;


  RequestDayMenuWidget({required this.orderData, required this.orderDate,this.selectListener});

  @override
  State<StatefulWidget> createState() => _RequestDayMenuState();
}

class _RequestDayMenuState
    extends BaseMvvmState<RequestDayMenuViewModel, RequestDayMenuWidget>
    with AutomaticKeepAliveClientMixin {
  @override
  Widget build(BuildContext context) {
    super.build(context);
    return initProvider();
  }

  @override
  Widget? buildLoadingContentView() {
    if (viewModel.menuData == null) {
      print("111111");
      return Container();
    }
    var type = viewModel.menuData!["type"];
    var list = viewModel.menuData!["menuList"] as List;

    if (type.toString() == "1") {
      ///常规
      print("22222");
      var menu = list.map((e) => RegularMenuData.fromJson(e)).toList();
      return FoodMenuContainerWidget(
        menuList: menu,
        orderData: widget.orderData,
        isRegular: true,
        selectListener: widget.selectListener,
        date: widget.orderDate,
      );
    }

    if (type.toString() == "2") {
      ///AB
      return Container();
    }
    if (type.toString() == "3") {
      ///几选几
      var menu = list.map((e) => RegularMenuData.fromJson(e)).toList();
      return FoodMenuContainerWidget(
        menuList: menu,
        orderData: widget.orderData,
        isRegular: false,
        selectListener: widget.selectListener,
        date: widget.orderDate,
      );
    }

    if (type.toString() == "4") {
      ///几选几
      var menu = list.map((e) => RegularMenuData.fromJson(e)).toList();
      return FoodMenuContainerWidget(
        menuList: menu,
        orderData: widget.orderData,
        isRegular: true,
        selectListener: widget.selectListener,
        date: widget.orderDate,
      );
    }

    return Container();
  }

  @override
  Widget buildRootView(BuildContext context, Widget loadingContentWidget) {
    return loadingContentWidget;
  }

  @override
  RequestDayMenuViewModel createViewModel() {
    return RequestDayMenuViewModel(context,
        orderData: widget.orderData, orderDate: widget.orderDate);
  }

  @override
  void onRetryClick() {
    viewModel.getWeekMenu();
  }

  @override
  bool get wantKeepAlive => true;
}
